<template>
    <div class="page">
        </div>
        <div class="weui-mask"></div>
        <div class="popup-qrcode">
            <div class="wrap">
                <h2>{{item.project_name}}</h2>
                <h3 v-show="item.group_name && item.project_name != item.group_name">{{item.group_name}}</h3>
                <!-- <div class="qrcode-box"><img src="../../static/imgs/qrcode.png" alt=""></div> -->
                <div class="qrcode-box"><img :src="item.qrcode_url" alt=""></div>
                <p class="tip">请通过灵云APP或微信扫描二维码加入项目</p>
            </div>
            <div class="btn-box com-border-top"><a @click="saveToAlbum(item.qrcode_url)">保存到相册</a><a @click="shareToWX(item.qrcode_url)">分享到微信</a></div>
            <div class="border"><span class="bl"></span><span class="bc"></span><span class="br"></span></div>
        </div>
</template>
 
<script>
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */
    import $ from 'zepto'
    import * as util from 'js/util.js'
    import clientInfo from 'gapi/clientInfo'
    import socialApi from 'clientApi/socialApi'
    import widget from 'gapi/widget'
    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */

    /**
     *  组件实例对象
     */
    export default {
        components: {

        },
        data: function(){
            return{
                item: {},
            }
        },
        vuex: {
            getters: {

            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){
              // alert(location.href)
              this.projectId = util.getUrddataString('pId')
              this.teamId = util.getUrddataString('tId')
              this.groupId = util.getUrddataString('gId')
              this.code = util.getUrddataString('code')
              console.log(this.code)
              // this.userId = util.getUrddataString('uId')
            },
            //获取二维码链接
            getQrCode() {
              let data = {
                  group_id: this.groupId,
                  team_id: this.teamId,
                  project_id : this.projectId,
                  type:this.code?this.code:''
              }
              console.log(data) 
              util.ajax({
                    url:'/group/qrcode',
                    type:'GET',
                    data:data,
                    timeout:10000,
                    beforeSend: () => {

                    },
                    success:(result) => {
                        console.log(result)
                        if(result.errno == 0){
                          this.item = result.data
                        }
                    },
                    error: (xhr, status) => {
                        // error
                        console.log(xhr)
                    },
                    complete: () => {

                    },
                    noNetwork: () => {
                        // 无网络的回调
                        widget.toast('网络连接失败，请检查网络')
                    }
                })
            },
            saveToAlbum (url){
                socialApi.downloadQRCodeImage(url, (data) => {
                    //todo
                    widget.toast('保存成功')
                })
            },
            shareToWX(url){
                socialApi.shareQRCode(url, (data) => {
                    // widget.toast('分享成功')
                })
            }
        },
        created(){

            this.init();

        },
        ready() {
          //获取二维码链接
            this.getQrCode()
          }
        }
</script>

<!-- CSS 样式 -->
<style src="../../node_modules/weui/dist/style/weui.css"></style>
<style src="../../static/css/common.css"></style>
<style src="../../static/css/user-list.css"></style>
